/*
 * UserFacade.java
 *
 * Created on 7 de Julho de 2007, 11:29
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package br.com.ecs.presentation.delegate;

import br.com.ecs.persistence.entity.SystemUser;
import br.com.ecs.persistence.facade.UserFacadeLocal;
import java.util.List;
import javax.ejb.Stateless;
import javax.naming.NamingException;

/**
 *
 * @author Danielle
 */
@Stateless
public class UserBusinessDelegate {

    private UserFacadeLocal userFacade;
    
    public UserBusinessDelegate(){
        //userFacade=lookupUserFacade();
        try {
          userFacade = ServiceLocator.getInstance().getUserFacadeLocal();
        } catch (NamingException ex) {
          ex.printStackTrace();
        }
    }
    
    private UserFacadeLocal lookupUserFacade() {
        
    try {
        javax.naming.Context c = new javax.naming.InitialContext();        
        UserFacadeLocal facade = (UserFacadeLocal) c.lookup("ecs/UserFacade/local");
        return facade;
    }
    catch(javax.naming.NamingException ne) {
        java.util.logging.Logger.getLogger(getClass().
                    getName()).log(java.util.logging.Level.SEVERE,"exception caught" ,ne);
        throw new RuntimeException(ne);
    }
}
    
    public void create(SystemUser user) {
        userFacade.create(user);
    }

    public void edit(SystemUser user) {
        userFacade.edit(user);
    }

    public void destroy(SystemUser user) {
        userFacade.destroy(user);
    }

    public SystemUser find(Object pk) {
        return (SystemUser) userFacade.find(pk);
    }
    
     public SystemUser findByName(String username) {
        return (SystemUser) userFacade.findByName(username);
    }

    public List findAll() {
        return userFacade.findAll();
    }

   public SystemUser findSystemUser(String login, String password) {
      return userFacade.findSystemUser(login, password);
   }
    
}
